Appendix 2D: OpenBUGS code for the multi-year single-count index model

This is similar to the time-trend N-mixture model, but only the first surveys are used.
Consequently the model only estimates the mean first count rather than estimating N.

Model {	

	a.N ~ dnorm(0,1)		# prior for log of expected count for average transect
	b.year ~ dnorm(0,1)	# average annual change in log count
	s.trans.N ~ dunif(0,5)		# SD in log expected count among transects
	tau.trans.N <-pow(s.trans.N,-2)	# convert to precision
		
	for (i in 1:n.transects) {		# for each transect...
		re.trans.N[i] ~ dnorm(0, tau.trans.N)	# assign random effect on log of expected count
	}

	for (i in 1:n.rows) {			# for each transect for each year...
		log(mu[i]) <- a.N + b.year*(year[i]-2012) + re.trans.N[transect[i]]	# calculate expected count 
		n[i,1] ~ dpois(mu[i])		# sample number found from no expected
		n.new[i,1] ~ dpois(mu[i])		# for posterior predictive check
	}
}